<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<link href="${basePath}/js/fileInput/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />
<!doctype html>
<html>
<head>
<style type="text/css">
	.ibox-content{
		border: none;
	}
	
	.progress {
   	 	margin-top: 15px!important;
   	 	margin-bottom:0px;
	}
	
	.ibox-zxsearchqu {
	    padding-bottom: 5px!important;
	}
</style>
</head>
<body class="gray-bg">
<div class="container creditbody">
	 <div class="iboxtitle">
	 	<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷后业务>申请代垫资>导入客户</span>
        </div>
         <div class="ibox-content ibox-zxsearchqu">
              <div class="uploadfile-btn">
		         <form  enctype="multipart/form-data">
					<input type="hidden" id="uploadName"/>
		          	<input id="uploadfile" name="uploadfile" type="file" multiple data-min-file-count="1"/>
		         </form>
	       	  </div>	
	       	  <div  class="uploadfile-btnb td-width">
	              	<select class="select-control" id="bankCode" name="bankCode"  >
					 </select>
	           </div>		
	          <div  class="uploadfile-btnc">
	          	  <button class="btn dpbtn_grey_heigth" type="button" onclick="preview();">导入预览</button>
	              <button class="btn dpbtn_grey_heigth" type="button" onclick="importList();">确认导入</button>
	          </div>
         </div>

         <div class="ibox-content">	
          	<div class="jqGrid_wrapper">
	             <table id="table_list_1"></table>
	             <div id="pager_list_1"></div>
         	</div>
         </div>
</div>
	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>	
    <script src="${basePath}/js/fileInput/js/fileinput.js" type="text/javascript"></script>
    <script src="${basePath}/js/fileInput/js/locales/zh.js" type="text/javascript"></script>
    <!-- custom js -->
    
    
    <!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
		var winWidth = $(window).width();
		var winHeight = $(window).height();
		var lastSel;
	    jQuery(function($) { 
	    	initTable();
	    	initBankDic();
    	    var fileBtn = $("input[type=file]");
    	    fileBtn.on("change", function(){
    	        var index = $(this).val().lastIndexOf("\\");
    	        var sFileName = $(this).val().substr((index+1));
    	        $("#rightText").html(sFileName);
    	    });
	    });
	    var initBankDic=function(){
	    	$.dpAjax({
		    	url:'${basePath}/DataDictionaryController/getEnableList',
		    	
	 			data:{
	 				"parentValue":"LoanBank"
	 			},
	 			success: function(datas){
	 				  if(datas.flag == "100100")
						  {
		 					  var result = datas.result.rows;
		 					  var programme_sel=[];
		 				      for(var i=0;i<result.length;i++){
		 				          var programme = result[i];
		 				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
		 				      }
		 				     $("#bankCode").html(programme_sel.join(' '));
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	              }
		    	});
	    }
    window.onresize = function()
    {
    	 $("#table_list_1").setGridWidth($(window).width()-80);
    	 $("#table_list_1").setGridHeight($(window).height() / 2.5);
    }
    var carSeriesChoose=function(){
    	
    }
	var carSeriesUnChoose=function(){
    	
    }
	var initTable=function(){
		var winWidth = $('div.ibox-content').width();
        var winHeight = document.body.offsetHeight - 300;
     	var win = winWidth / 7 - 20;
 	    $.jgrid.defaults.styleUI = 'Bootstrap';
 	    var initFlag=true;
 	    var name=$("#uploadName").val();
		$("#table_list_1").jqGrid({
			url:'${basePath}/DhInsteadPaymentController/preview',
	       	datatype : "json",
	       	postData:{"name":name,"initFlag":initFlag},
		    colNames : ['客户姓名','身份证号','卡号', '逾期天数','当前余额(代偿金额)', '最低还款额', '透支本金','透支利息','分期付款授权累计','违约金连续收取次数','当前逾期期限段'],
		    colModel : [ 
	             {name: 'cusName',index: 'cusName',width: 150,align: "center",sorttype: "float"},
	             {name: 'cusNo',index: 'cusNo',width: 170,align: "center",sorttype: "float"},
	             {name: 'cardNo',index: 'cardNo',width: 170,align: "center",sorttype: "float"},
	             {name: 'dateNumOverdue',index: 'dateNumOverdue',width: 150,align: "center",sorttype: "float"},
	             {name: 'balance',index: 'balance',width: 150,align: "center",sorttype: "float",hidden:true},
	             {name: 'amountLowest',index: 'amountLowest',width: 150,align: "center",sorttype: "float"},
	             {name: 'principleOverdraft',index: 'principleOverdraft',width: 150,align: "center",sorttype: "float"},
	             {name: 'interestOverdraft',index: 'interestOverdraft',width: 150,align: "center",sorttype: "float"},
	             {name: 'accreditTotal',index: 'accreditTotal',width: 150,align: "center",sorttype: "float"},
	             {name: 'numContinuous',index: 'numContinuous',width: 150,align: "center",sorttype: "float"},
	             {name: 'stage',index: 'stage',width: 150,align: "center",sorttype: "float"}
	             ],
	           mtype : "post",
	           height: winHeight,
	           width:winWidth,  
	           autowidth: false,
	           shrinkToFit: false,
	           rowNum: 50,
// 	           rowList: [10, 20, 30,40,50],
	           viewrecords: true,
	           pager: "#pager_list_1",
	           hidegrid: false,
	           multiselect : false,		//实现单选    multiboxonly:true   beforeSelectRow: true,
	           multiboxonly:false,  
	           beforeSelectRow: false,
	           altRows:true,
		          altclass:'someClass',
	           loadComplete: function(datas){
	        	   if(datas.flag==100100){
	        		   if(initFlag==false){
		        		   layer.msg('预览成功！', {icon: 6});
	        		   }
		        		   return;
	        	   }
	        	   if(datas.flag == '100802') {
		 				  top.location.href = thisLoginUrl;
		 				  return;
		 			 }
	        	   if(datas.flag==100300){
	        		   $.fn.showDatas({"datas":datas});
	        		   return;
	        	   }
	        	   if(datas.flag == "101802")
	                  {
						  layer.msg('请选择正确的银行模板导入！', {icon: 8});
	                	  return;
	                  }
	        	   return ;
	           },
	           jsonReader: {
	                root: "result.rows",
	                page: "result.page",
	                total: "result.total",
	                records: "result.records",
	                repeatitems: false,
	                id: "replaceId"
	            }
	      });
	}
	var importList=function(){
		var name=$("#uploadName").val();
		if(name==""){
			 layer.msg('请先上传excel后再执行预览！', {icon: 5});
			return false;
		}
		 var bankCode=$('#bankCode option:selected').val();
		$.dpAjax({
    		url:'${basePath}/DhInsteadPaymentController/batchImport',
    		data:{"name":name,"bankCode":bankCode},
			success: function(datas){
    			  if(datas.flag == "100100")
				  {
					  layer.msg('执行成功！', {icon: 6});
					  return;
				  }
    			  if(datas.flag == "101802")
                  {
					  layer.msg('请选择正确的银行模板导入！', {icon: 8});
                	  return;
                  }
				  if(datas.flag == "100200")
                  {
					  $.fn.showDatas({"datas":datas});
                	  return;
                  }
            }
    	});
	}
	var preview=function(){
		var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
    	var data = {};
    	var uploadfile = $("#uploadName").val();
  	    if(uploadfile==""){
  	    	layer.msg('请先上传表格，再预览！', {icon: 5});
  	    	return false;
  	    }
  	  var bankCode=$('#bankCode option:selected').val();
    	data.name =$("#uploadName").val() || '';
    	data.bankCode=bankCode;
    	data.initFlag=false;
    	$.extend(postData, data);
		$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}])
	}
	$("#uploadfile").fileinput({
	   	 language: 'zh', //设置语言
	   	 uploadUrl: "${basePath}/FileController/upload", //上传的地址(访问接口地址)
	   	 allowedFileExtensions: ['xlsx'],//接收的文件后缀
	   	 showUpload: false, //是否显示上传按钮
	   	 showRemove : false, //显示移除按钮
	   	 showPreview : false, //是否显示预览
	   	 dropZoneEnabled: false,//是否显示拖拽区域
	   	 minImageWidth:'1',
	   	uploadExtraData:{"flag":true},
	  	}).on("filebatchselected", function(event, files) {
            $(this).fileinput("upload");
        })
        .on("fileuploaded", function(event, datas) {
        	jQuery("#table_list_1").jqGrid("clearGridData");
        	 if(datas.response.flag==100100){
		  			$("#uploadName").val(datas.response.result.name);
		  }
    });
	
    </script>
</body>
</html>
